home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / bascrypt.bas < prev    next >
BASIC Source File  |  1991-02-27  |  2KB  |  46 lines

  1. 'BasEncrypt:  Encryption/decryption routine
  2.  
  3. 'Nelson Ford, Public (software) Library
  4. 'P.O.Box 35705, Houston, TX 77235-5705
  5. 'Call for free newsletter: 800-2424-PSL
  6. 'Information: 713-524-6394.  CIS#: 71355,470
  7.  
  8. 'This file can be freely used and copied for others so long as the file
  9. 'is not changed in any way.
  10.  
  11. 'Purpose:
  12. '''''''''
  13. 'Someone asked on the MSSYS forum on CompuServe for a simple encryption routine
  14. 'and the old XOR method was recommended.
  15.  
  16. 'The accompanying routine is a lot more secure and just about as easy.
  17.  
  18. 'Algorithm:
  19. '''''''''''
  20. 'The idea is to set up a look-up substitution string for the ASCII character
  21. 'set, and replace each character in your text with the character assigned to
  22. 'that character's ASCII number position in the look-up string.
  23.  
  24. 'In the sample code, the ASCII character set is simply reversed in the
  25. 'encryption string ("e$"). In actual use, you should assign the characters to
  26. 'the string more randomly. You should probably NOT change control characters
  27. '[eg: leave the 13th character in the substitution string as CHR$(13)]
  28. 'so that you do not lose the ability to do INPUTs.
  29.  
  30. DEFINT A -Z: E$ = SPACE$(255) : D$ = SPACE$(255)
  31.  
  32. FOR I = 1 TO 255: MID$(E$, 256-I, 1) = CHR$(I): NEXT
  33. FOR I = 1 TO 255: MID$(D$, ASC( MID$(E$,I))) = CHR$(I): NEXT
  34.  
  35. LINE INPUT "Enter text to encrypt: "; T$
  36. FOR I = 1 TO LEN(T$)
  37.   MID$(T$, I, 1) = MID$(E$, ASC( MID$(T$, I)))
  38. NEXT
  39. PRINT T$
  40.  
  41. INPUT "Ready to decrypt"; x$
  42. FOR I = 1 TO LEN(T$)
  43.   MID$(T$, I, 1) = MID$(D$, ASC( MID$(T$, I)))
  44. NEXT
  45. PRINT T$
  46.